﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Input;

using System.Windows;

using GWApplication;


namespace GWPresentation
{
    public static class GisCommandBinder
    {

        static RoutedCommand select = new RoutedCommand();

        public static RoutedCommand Select
        {
            get { return GisCommandBinder.select; }
          
        }


        static RoutedCommand pan = new RoutedCommand();

        public static RoutedCommand Pan
        {
            get { return GisCommandBinder.pan; }


        }


        static RoutedCommand addPoint = new RoutedCommand();

        public static RoutedCommand AddPoint
        {
            get { return GisCommandBinder.addPoint; }
           
        }


        static RoutedCommand addLine = new RoutedCommand();

        public static RoutedCommand AddLine
        {
            get { return GisCommandBinder.addLine; }
          
        }


         /// <summary>
        /// 将命令绑定到窗体
        /// </summary>
        /// <param name="window"></param>
        public static void BindCommandsToWindow(Window window)
        {


            CommandBinding cbSelect = new CommandBinding();
            cbSelect.Command = select;
            cbSelect.Executed += new ExecutedRoutedEventHandler(cbSelect_Executed);
            cbSelect.CanExecute += new CanExecuteRoutedEventHandler(cbSelect_CanExecute);

            window.CommandBindings.Add(cbSelect);


            CommandBinding cbAddNode = new CommandBinding();
            cbAddNode.Command = addPoint;
            cbAddNode.Executed += new ExecutedRoutedEventHandler(cbAddNode_Executed);
            cbAddNode.CanExecute += new CanExecuteRoutedEventHandler(cbAddNode_CanExecute);

            window.CommandBindings.Add(cbAddNode);


            CommandBinding cbAddLine = new CommandBinding();
            cbAddLine.Command = addLine;
            cbAddLine.Executed += new ExecutedRoutedEventHandler(cbAddLine_Executed);
            cbAddLine.CanExecute += new CanExecuteRoutedEventHandler(cbAddLine_CanExecute);

            window.CommandBindings.Add(cbAddLine);



        }

        static void cbAddNode_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (AppViewModel.Current.TvProject.SelectedVM is TvLayerVM)
            {
                e.CanExecute = true;


            }

            e.Handled = true;

        }

        static void cbAddNode_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            GisService.CurrentService.AddPoint();
        }

        static void cbAddLine_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            if (AppViewModel.Current.TvProject.SelectedVM is TvLayerVM)
            {
                e.CanExecute = true;
               
                
            }

            e.Handled = true;
           
        }

        static void cbAddLine_Executed(object sender, ExecutedRoutedEventArgs e)
        {

            GisService.CurrentService.AddLine();

           
        }

        static void cbSelect_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
           
        }

        static void cbSelect_Executed(object sender, ExecutedRoutedEventArgs e)
        {
           
        }






    }
}
